/*
 * OperationsMgr.java
 *
 * Created on April 4, 2007, 6:07 PM
 *
 */

package localSite;

import localSite.vendingMachineDB.NoRacleVendingMachine;
import localSite.vendingMachineDB.VendingMachineRecord;
import java.util.LinkedList;
import java.util.ListIterator;

/**
 *
 * @author David Roberts
 */
public class OperationsMgr
{
    private NoRacleVendingMachine vendDB;   
    
    // Constructor
    public OperationsMgr ()
    {
        System.out.println("Creating Operations Manager");
        vendDB = new NoRacleVendingMachine ();
    }
    
    /* Creates a new instance of OperationsMgr
    public OperationsMgr (int numMachines)
    {
        int ID = 0;
        String location = null;
        String lessor = null;
        Object[] sHistory = null;
        Object[] vCatalog = null;
     
        // Read in file describing vending machines
        // numMachines = total number of vending machines under control of this office
        for (int i = 0; i < numMachines; i++)
        {
            // As each block of data representing a single machine is read in:
            // (ID = vending machine identification number)
            // (location = description of machine's location)
            // (lessor = description of who this location is leased from)
            // (sHistory = history of service actions performed on this machine)
            // (vCatalog = inventory of machine)
            // Note that the machine's status will automatically be set to UNKNOWN. A later 'ping' will resolve the machine's status.
            machineArray[machineIdx++] = new VendingMachine (ID, location, lessor, sHistory, vCatalog);
            pingMachine (ID);
        }
    }
     */
    
    public void addVendingMachine (VendingMachineRecord vend)
    {
        vendDB.AddRecord (vend);
        activateMachine (vend.machineID);
        pingMachine (vend.machineID);
    }
    
    public void removeVendingMachine (int machineID)
    {
        deactivateMachine (machineID);
        vendDB.DeleteRecord (machineID);
    }
    
    public void dispatchTechnician (int serviceTicket)
    {
        // This method will assign a technician to a particular service ticket.
    }
    
    public Object createOperationsReport (Object machineIDs, String dates)
    {
        // This method will create a report based on operational data of one or more machines.
        return null;
    }
    
//    private void updateMachineSoftware (int machineID)
//    {
//        // This method will update a vending machine's software.
//    }
    
    private boolean activateMachine (int machineID)
    {
        // This method will activate a vending machine so that it accepts transactions from customers.
        // The return value will indicate whether the activation was successful (true) or not (false).
        VendingMachineRecord vend = vendDB.GetRecord (machineID);
        if( vend != null )
        {
            System.out.println ("Turning on Machine: " + machineID );
            ///vend.status = ACTIVE;
        }
        return true;
    }
    
    private boolean deactivateMachine (int machineID)
    {
        // This method will deactivate a vending machine so that it does not accept transactions from customers.
        // The return value will indicate whether the deactivation was successful (true) or not (false).
        System.out.println ("Turning Off Machine: " + machineID );
        return true;
    }
    
    private boolean pingMachine (int machineID)
    {
        // This method will "ping" a vending machine to determine whether it is still responsive.
        // A return value of true indicates that the machine responded within a reasonable amount of time;
        // false indicates that no response was received in a timely manner.
        System.out.println ("Machine: " + machineID + " active.");
        return true;
    }
    

//    public int createServiceTicket (Object stInformation)
//    {
//        // This method will create a new service ticket based on a problem with a specific vending machine.
//        // The return value is the service ticket ID number (integer value).
//        ServiceTicket ticket = new ServiceTicket ();
//     
//        return ticket.ID;
//    }
    

//    public void updateServiceTicket (ServiceTicket ticket)
//    {
//        // This method will allow a service ticket to be updated.
//    }

}
